import O1HD from "../../engines/gameEngine";
import level_goldMiner from "../../levelBundles/level_goldMiner/level_goldMiner";
import InGamePage from "./InGamePage";

const {ccclass, property} = cc._decorator;

@ccclass
export default class goldMinerInGamePage extends InGamePage {

    @property({type:cc.Label,tooltip:"倒计时文本"})
    lbTime:cc.Label = null;

    @property({type:cc.Node,tooltip:"目标节点"})
    targetNode:cc.Node = null;

    @property({type:cc.Label,tooltip:"测试文本"})
    lbTest:cc.Label = null;

    @property({type:cc.Node,tooltip:"titleNode"})
    titleNode:cc.Node = null;

    @property({type:cc.Node,tooltip:"titleNode"})
    stepNode:cc.Node = null;

    @property()
    testFlag:boolean = false;

    level:level_goldMiner = null;

    start(): void {
        this.scheduleOnce(()=>{
            cc.tween(this.titleNode).to(1,{opacity:0}).start();
            cc.tween(this.stepNode).to(1,{opacity:255}).start();
        },3); 
    }

    bindLevel(level:level_goldMiner){
        this.level = level;
        this.refrenshStep();
    }

    refrenshTime(){
        this.lbTime.string = this.level.curCountDown.toString();
    }

    async showTargetNode(targetMoney:number){
        let node:cc.Node = cc.instantiate(this.targetNode);
        node.active = true;
        let targetLb:cc.Label = node.getChildByName("label").getComponent(cc.Label);
        targetLb.string = `目标：${targetMoney}`;
        let shceduleLb:cc.Label = node.getChildByName("lbSchedule").getComponent(cc.Label);
        shceduleLb.string = `进度：${this.level.gameStep + 1}/${this.level.targetMoneyAry.length}`;
        node.setParent(this.level.node);
        node.setPosition(this.level.cameraNode.position);
        node.scale = 1 / this.level.cameraNode.getComponent(cc.Camera).zoomRatio;
        let pos:cc.Vec2 = this.level.lbMoney.node.parent.getPosition();
        await new Promise<void>(resolve=>{
            //@ts-ignore
            cc.tween(node).delay(2).to(0.5,{position:pos,scale:0}).call(()=>{
                resolve();
                this.level.targetLbAni();
                node.destroy();
                node.removeFromParent();
            }).start();
        });
    }

    refrenshStep(){
        let lb:cc.Label = this.stepNode.getChildByName("lbStep").getComponent(cc.Label);
        lb.string = `${this.level.gameStep + 1}/${this.level.targetMoneyAry.length}轮`;
    }

    update(dt: number){
        if(CC_DEBUG && this.testFlag)
        this.lbTest.string = `钻石加成：${O1HD.getManagers().goldMinerManager.diamondPrice}\n宝箱加成：${O1HD.getManagers().goldMinerManager.boxPrice}\n 全部加成：${O1HD.getManagers().goldMinerManager.allPrice}\n钩子速度加成：${O1HD.getManagers().goldMinerManager.getAdditionByLevel().toFixed(2)}`;
    }
    
}
